package com.arelikebrothers.demo.spring.ioc.resource;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.FileSystemUtils;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

/**
 * Created by lennon on 23/05/2017.
 */
public class ResourceDemo {
    public static void main(String[] args) {
        ClassPathResource classPathResource = new ClassPathResource("sample.xml");
        System.out.println(classPathResource.getFilename());

        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        try {

            Resource[] resources = resolver.getResources("classpath:*e.xml");
            Arrays.asList(resources).forEach((resource -> {
                try {
                    System.out.println(resource.getFilename());
                    System.out.println(resource.contentLength());
                    System.out.println(resource.getDescription());
                    System.out.println(resource.getFile());

                    FileCopyUtils.copy(resource.getFile(), resource.createRelative("haha.xml").getFile());

                } catch (IOException e) {
                    e.printStackTrace();
                }

            }));
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
